# -*- encoding: utf-8 -*-
"""
@Author  :   BillFun
@License :   (C) Copyright 2013-2017, JieInfo
@Software:   PyCharm
@File    :   until.py
@Time    :   2018/3/27 23:47
@Desc    :
"""
from datetime import datetime


def is_month(month_str):
    month_str = month_str.rstrip()
    # 判断长度是否正常，判断是否为数字
    if len(month_str) != 6 or not month_str.isalnum():
        return False

    mon = int(month_str[4:])
    if mon < 0 or mon > 12:
        return False

    return True


def get_last_month():
    d = datetime.now()
    year = d.year
    month = d.month

    if month == 1:
        month = 12
        year -= 1
    else:
        month -= 1

    return datetime(year, month,1).strftime('%Y%m')


if __name__ == '__main__':
    aaa = is_month('201815')
    print(aaa)
    if aaa is True:
        print('It\'s True')

    bbb = aaa + 1
    print(bbb)

    if bbb is True:
        print('bbb,It\'s True')

    print(get_last_month())
